package me.zhengjie.modules.system.service.dto

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.base.BaseDTO
import me.zhengjie.common.utils.JacksonUtil
import org.apache.commons.lang3.builder.ToStringBuilder

import java.sql.Timestamp
/**
 * @author Kuki Wu
 * @date 2019-04-10
 */

@JsonTypeName("DictDTO")
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
data class DictDTO(
    var id: Long? = null,

    @get:JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
    @get:JsonInclude(JsonInclude.Include.NON_EMPTY)
    var dictDetails: MutableSet<DictDetailDTO>? = mutableSetOf(),

    var name: String? = null,

    var description: String? = null,

): BaseDTO(){
    annotation class Update

    companion object {
        fun fromJson(json: String): DictDTO? {
            val obj=JacksonUtil.parseObject(json, DictDTO::class.java)!!
            return when(obj){
                is DictDTO -> obj
                else -> null
            }
        }
    }

    fun copy(source: DictDTO?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}